package com.longge;

import java.util.*;
import java.util.stream.Collectors;

public class HalfQuestions {
    public int halfQuestions(int[] questions) {

        HashMap<Integer, Integer> countMap = new HashMap<>();
        for (int question : questions) {
            countMap.put(question, countMap.getOrDefault(question, 0) + 1);
        }

        int n = questions.length / 2, num = 0;
        List<Integer> nums = countMap.values().stream().sorted(Comparator.comparing(Integer::intValue).reversed()).collect(Collectors.toList());
        for (Integer key : nums) {
            if (n > 0) {
                n = n - key;
                num++;
            }
        }

        return num;

    }

    public static void main(String[] args) {
        HalfQuestions halfQuestions = new HalfQuestions();
        halfQuestions.halfQuestions(new int[]{1,5,1,3,4,5,2,5,3,3,8,6});
    }

}
